<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<script type="text/ecmascript" src="../../resources/js/md5.js"></script>
	<script type="text/ecmascript" src="../../resources/js/sha1.js"></script>
	<script type="text/ecmascript" src="../../resources/js/base64.js"></script>
	<script type="text/javascript">
	function trans(){
	  var hash = hex_md5(document.getElementById("text").value);
	  document.getElementById("result1").value = hash;
	  document.getElementById("result12").value = hex_md5(hash);
	  document.getElementById("result13").value = hex_md5(hex_md5(hash));

	  document.getElementById("result2").value = hex_sha1(document.getElementById("text").value);
	  var base64 = new Base64();
	  document.getElementById("result3").value = base64.encode(document.getElementById("text").value);
	  document.getElementById("result31").value = base64.decode(document.getElementById("result3").value);
	}
	function hash(){
	  var pass = document.getElementById("pwd").value;
	  frm.pwd.value = hex_md5(frm.pwd.value);
	  frm.result4.value = hex_md5(frm.pwd.value);
	  //document.getElementById("result4").value = hex_md5(pass);
	  document.getElementById("result5").value = hex_sha1(pass);
	  var base64 = new Base64();
	  document.getElementById("result6").value = base64.encode(pass);
	  document.getElementById("result61").value = base64.decode(document.getElementById("result6").value);
	}
	function submit(){
	  //默认的提交处理，自定义的提交前处理方法不要用submit作为函数名
	  hash();
	//onsubmit="pwd.value =hex_md5(pwd.value)"
	}
	
	</script>
</head>
<body>
	<p>MD5/SHA1/BASE64散列示例：</p>	
	<p>转换前：<input type="text" id="text" style="width:200px" value="abc" /></p>
	
	<p>MD5转换后：<input type="text" id="result1" style="width:300px" /></p>
	<p>MD5转换后2：<input type="text" id="result12" style="width:300px" /></p>
	<p>MD5转换后3：<input type="text" id="result13" style="width:300px" /></p>
	<p>SHA1转换后：<input type="text" id="result2" style="width:300px" /></p>
	<p>BASE64转换后：<input type="text" id="result3" style="width:300px" /></p>
	<p>BASE64转换后转回：<input type="text" id="result31" style="width:300px" /></p>
	
	<p><input type="button" value=" MD5/SHA1/BASE64 " onClick="trans()" /></p>
	
	<form name="frm" >
		<p>name: <input type="text" id="name" style="width:200px" /> </p>		
		<p>password: <input type="password" id="pwd" style="width:200px" /></p>	
			
		<p><input type="button" value="FORM散列MD5/SHA1/BASE64" onClick="hash()" /></p>
		
		<p>MD5散列后的密码：<input type="text" id="result4" style="width:300px" /></p>
		<p>SHA1散列后的密码：<input type="text" id="result5" style="width:300px" /></p>
		<p>BASE64散列后的密码：<input type="text" id="result6" style="width:300px" /></p>
		<p>BASE64散列后转回的密码：<input type="text" id="result61" style="width:300px" /></p>
	</form>
</body>
</html>
